#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>

using namespace std;

bool IsRepeat(char* arr, int n)
{
    for (int i = 0; i < n; i++)
    {
        int count = 0;
        for (int j = 0; j < n; j++)
        {
            if (arr[i] == arr[j])
            {
                count++;
            }
        }
        if (count >= 2)
        {
            return true;
        }
    }
    return false;
}

bool isValidSudoku(char** board, int boardSize, int* boardColSize)
{
    char arr[11] = { 0 };
    int index = 0;
    for (int i = 0; i < boardSize; i++)
    {
        if (i % 3 == 0)
        {
            int begin = i, end1 = i + 3, end2 = end1;
            for (int temp = 0; temp < 3; temp++)
            {
                index = 0;
                for (int j = i; j < end1; j++)
                {
                    for (int k = begin; k < end2; k++)
                    {
                        if (board[j][k] != '.')
                        {
                            arr[index++] = board[j][k];
                        }
                    }
                }
                if (IsRepeat(arr, index))
                {
                    return false;
                }
                begin += 3;
                end2 += 3;
            }
        }
        index = 0;
        for (int j = 0; j < boardSize; j++)
        {
            if (board[i][j] != '.')
            {
                arr[index++] = board[i][j];
            }
        }
        if (IsRepeat(arr, index))
        {
            return false;
        }
        index = 0;
        for (int j = 0; j < boardSize; j++)
        {
            if (board[j][i] != '.')
            {
                arr[index++] = board[j][i];
            }
        }
        if (IsRepeat(arr, index))
        {
            return false;
        }
    }
    return true;
}

int main()
{
    char board[10][10] = { 0 };
    strcpy(board[0], "53..7....");
    strcpy(board[1], "6..195...");
    strcpy(board[2], ".98....6.");
    strcpy(board[3], "8...6...3");
    strcpy(board[4], "4..8.3..1");
    strcpy(board[5], "7...2...6");
    strcpy(board[6], ".6....28.");
    strcpy(board[7], "...419..5");
    strcpy(board[8], "....8..79");
    
    char arr[11] = { 0 };
    int index = 0, boardSize = 9;
    bool ret = true;
    for (int i = 0; i < boardSize; i++)
    {
        if (i % 3 == 0)
        {
            int begin = i, end1 = i + 3, end2 = end1;
            for (int temp = 0; temp < 3; temp++)
            {
                index = 0;
                for (int j = i; j < end1; j++)
                {
                    for (int k = begin; k < end2; k++)
                    {
                        if (board[j][k] >= '0' && board[j][k] <= '9')
                        {
                            arr[index++] = board[j][k];
                        }
                    }
                }
                if (IsRepeat(arr, index))
                {
                    ret = false;
                }
                begin += 3;
                end2 += 3;
            }
        }
        index = 0;
        for (int j = 0; j < boardSize; j++)
        {
            if (board[i][j] >= '0' && board[i][j] <= '9')
            {
                arr[index++] = board[i][j];
            }
        }
        if (IsRepeat(arr, index))
        {
            ret = false;
        }
        index = 0;
        for (int j = 0; j < boardSize; j++)
        {
            if (board[j][i] >= '0' && board[j][i] <= '9')
            {
                arr[index++] = board[j][i];
            }
        }
        if (IsRepeat(arr, index))
        {
            ret = false;
        }
    }

    return 0;
}